from conn_mysql import ApiSql
import datetime
class ResetPwd(ApiSql):

    def reset(self,phone,verify_code,new_password,cnew_password,methods):

        if methods !='POST':

            return {'status':-1,'errorCode':1,'errorMsg':'请检查你的方法应该为POST','resultBody':None}

        if  not all((phone,verify_code,new_password,cnew_password)):

            return {'status':-1,'errorCode':2,'errorMsg':'请检查你的参数','resultBody':None}
    
        if new_password != cnew_password:

            return {'status': -1,'errorCode': 3,'errorMsg': '两次密码不一致','resultBody':None}

        result=self.select_user_info(phone)

        if result:

            info=self.select_code(phone,verify_code)

            if info:
                time_delta=datetime.timedelta(minutes=5)
                register=info['register_time']
                if (time_delta+register)<datetime.datetime.now():

                    return {
                        "status": -1,
                        "errorCode": 2,
                        "errorMsg": '验证码超时，请重新申请新验证码',
                        "resultBody": None,
                    }

                res=self.update_login_password(phone,new_password)

                return {'status': 1,'errorCode': None,'errorMsg': None,'resultBody':'密码修改成功'}

            else:

                return {'status': -1,'errorCode': 5,'errorMsg': '验证码不正确','resultBody': None}

        else:

            return {'status': -1,'errorCode': 3,'errorMsg': '用户名不存在','resultBody':None}
                
                







            

        



        

